﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace FiberRMS.DAL.AlarmManager
{
    /// <summary>
    /// 数据访问类ALARM_FAULTBILL。
    /// </summary>
    public class ALARM_FAULTBILL
    {
        public ALARM_FAULTBILL()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string BILLID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ALARM_FAULTBILL");
            strSql.Append(" where BILLID=:BILLID ");
            OracleParameter[] parameters = {
					new OracleParameter(":BILLID", OracleType.VarChar,50)};
            parameters[0].Value = BILLID;

            return OracleHelper.Exists(strSql.ToString(), parameters);
        }
        public object GetMaxID(DateTime dt)
        {
            return OracleHelper.GetSingle("SELECT max(substr(BILLID,9,4)) ID FROM ALARM_FAULTBILL WHERE substr(billid,0,6) = '" + dt.ToString("yyyyMM") + "'");            
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(FiberRMS.Model.AlarmManager.ALARM_FAULTBILL model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ALARM_FAULTBILL(");
            strSql.Append("BELONGDOMAIN,BILLID,ALARMNUMBER,ALARMLEVEL,PRIMALCAUSE,STARTTIME,GENERICTIME,DISPATCHDESC,DISPOSETIME,DISPOSESTATUS,REMARK)");
            strSql.Append(" values (");
            strSql.Append(":BELONGDOMAIN,:BILLID,:ALARMNUMBER,:ALARMLEVEL,:PRIMALCAUSE,:STARTTIME,:GENERICTIME,:DISPATCHDESC,:DISPOSETIME,:DISPOSESTATUS,:REMARK)");
            OracleParameter[] parameters = {
					new OracleParameter(":BELONGDOMAIN", OracleType.VarChar,40),
					new OracleParameter(":BILLID", OracleType.VarChar,20),
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,40),
					new OracleParameter(":ALARMLEVEL", OracleType.VarChar,64),
					new OracleParameter(":PRIMALCAUSE", OracleType.VarChar,200),
					new OracleParameter(":STARTTIME", OracleType.DateTime),
					new OracleParameter(":GENERICTIME", OracleType.DateTime),
					new OracleParameter(":DISPATCHDESC", OracleType.VarChar,400),
					new OracleParameter(":DISPOSETIME", OracleType.DateTime),
					new OracleParameter(":DISPOSESTATUS", OracleType.VarChar,200),
					new OracleParameter(":REMARK", OracleType.VarChar,400)};
            parameters[0].Value = model.BELONGDOMAIN;
            parameters[1].Value = model.BILLID;
            parameters[2].Value = model.ALARMNUMBER;
            parameters[3].Value = model.ALARMLEVEL;
            parameters[4].Value = model.PRIMALCAUSE;
            parameters[5].Value = model.STARTTIME;
            parameters[6].Value = model.GENERICTIME;
            parameters[7].Value = model.DISPATCHDESC;
            parameters[8].Value = model.DISPOSETIME;
            parameters[9].Value = model.DISPOSESTATUS;
            parameters[10].Value = model.REMARK;

            int i = OracleHelper.ExecuteSql(strSql.ToString(), parameters);
            return i > 0 ? true : false;
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(FiberRMS.Model.AlarmManager.ALARM_FAULTBILL model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ALARM_FAULTBILL set ");
            strSql.Append("BELONGDOMAIN=:BELONGDOMAIN,");
            strSql.Append("ALARMNUMBER=:ALARMNUMBER,");
            strSql.Append("ALARMLEVEL=:ALARMLEVEL,");
            strSql.Append("PRIMALCAUSE=:PRIMALCAUSE,");
            strSql.Append("STARTTIME=:STARTTIME,");
            strSql.Append("GENERICTIME=:GENERICTIME,");
            strSql.Append("DISPATCHDESC=:DISPATCHDESC,");
            strSql.Append("DISPOSETIME=:DISPOSETIME,");
            strSql.Append("DISPOSESTATUS=:DISPOSESTATUS,");
            strSql.Append("REMARK=:REMARK");
            strSql.Append(" where BILLID=:BILLID ");
            OracleParameter[] parameters = {
					new OracleParameter(":BELONGDOMAIN", OracleType.VarChar,40),
					new OracleParameter(":BILLID", OracleType.VarChar,20),
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,40),
					new OracleParameter(":ALARMLEVEL", OracleType.VarChar,64),
					new OracleParameter(":PRIMALCAUSE", OracleType.VarChar,200),
					new OracleParameter(":STARTTIME", OracleType.DateTime),
					new OracleParameter(":GENERICTIME", OracleType.DateTime),
					new OracleParameter(":DISPATCHDESC", OracleType.VarChar,400),
					new OracleParameter(":DISPOSETIME", OracleType.DateTime),
					new OracleParameter(":DISPOSESTATUS", OracleType.VarChar,200),
					new OracleParameter(":REMARK", OracleType.VarChar,400)};
            parameters[0].Value = model.BELONGDOMAIN;
            parameters[1].Value = model.BILLID;
            parameters[2].Value = model.ALARMNUMBER;
            parameters[3].Value = model.ALARMLEVEL;
            parameters[4].Value = model.PRIMALCAUSE;
            parameters[5].Value = model.STARTTIME;
            parameters[6].Value = model.GENERICTIME;
            parameters[7].Value = model.DISPATCHDESC;
            parameters[8].Value = model.DISPOSETIME;
            parameters[9].Value = model.DISPOSESTATUS;
            parameters[10].Value = model.REMARK;

            int i = OracleHelper.ExecuteSql(strSql.ToString(), parameters);
            return i > 0 ? true : false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string BILLID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete ALARM_FAULTBILL ");
            strSql.Append(" where BILLID=:BILLID ");
            OracleParameter[] parameters = {
					new OracleParameter(":BILLID", OracleType.VarChar,50)};
            parameters[0].Value = BILLID;

            int i = OracleHelper.ExecuteSql(strSql.ToString(), parameters);
            return i > 0 ? true : false;
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FiberRMS.Model.AlarmManager.ALARM_FAULTBILL GetModel(string BILLID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select BELONGDOMAIN,BILLID,ALARMNUMBER,ALARMLEVEL,PRIMALCAUSE,STARTTIME,GENERICTIME,DISPATCHDESC,DISPOSETIME,DISPOSESTATUS,REMARK from ALARM_FAULTBILL ");
            strSql.Append(" where BILLID=:BILLID ");
            OracleParameter[] parameters = {
					new OracleParameter(":BILLID", OracleType.VarChar,50)};
            parameters[0].Value = BILLID;

            FiberRMS.Model.AlarmManager.ALARM_FAULTBILL model = new FiberRMS.Model.AlarmManager.ALARM_FAULTBILL();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.BELONGDOMAIN = ds.Tables[0].Rows[0]["BELONGDOMAIN"].ToString();
                model.BILLID = ds.Tables[0].Rows[0]["BILLID"].ToString();
                model.ALARMNUMBER = ds.Tables[0].Rows[0]["ALARMNUMBER"].ToString();
                model.ALARMLEVEL = ds.Tables[0].Rows[0]["ALARMLEVEL"].ToString();
                model.PRIMALCAUSE = ds.Tables[0].Rows[0]["PRIMALCAUSE"].ToString();
                if (ds.Tables[0].Rows[0]["STARTTIME"].ToString() != "")
                {
                    model.STARTTIME = DateTime.Parse(ds.Tables[0].Rows[0]["STARTTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GENERICTIME"].ToString() != "")
                {
                    model.GENERICTIME = DateTime.Parse(ds.Tables[0].Rows[0]["GENERICTIME"].ToString());
                }
                model.DISPATCHDESC = ds.Tables[0].Rows[0]["DISPATCHDESC"].ToString();
                if (ds.Tables[0].Rows[0]["DISPOSETIME"].ToString() != "")
                {
                    model.DISPOSETIME = DateTime.Parse(ds.Tables[0].Rows[0]["DISPOSETIME"].ToString());
                }
                model.DISPOSESTATUS = ds.Tables[0].Rows[0]["DISPOSESTATUS"].ToString();
                model.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select BELONGDOMAIN,BILLID,ALARMNUMBER,ALARMLEVEL,PRIMALCAUSE,STARTTIME,GENERICTIME,DISPATCHDESC,DISPOSETIME,DISPOSESTATUS,REMARK ");
            strSql.Append(" FROM ALARM_FAULTBILL ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return OracleHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "ALARM_FAULTBILL";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

